<?php

namespace StarCloud\Library\Sdk;

use Phalcon\Di;

class KsOpen
{
    private $app_id;
    private $secret;
    private $callback;

    const OAUTH_PREFIX = "https://open.kuaishou.com";
    const OAUTH_AUTHORIZE_URL = "/oauth2/authorize?";

    const QRCODE_URL = "/oauth2/qr_code?";

    public function __construct($config)
    {
        $this->app_id = $config['app_id'];
        $this->secret = $config['secret'];
        $this->callback = $config['callback'];
    }

    /**
     * oauth 授权跳转接口
     * @param string $callback 回调URI
     * @return string
     */
    public function getOauthRedirect($callback, $state='', $scope='snsapi_userinfo')
    {
        return self::OAUTH_PREFIX.self::OAUTH_AUTHORIZE_URL.'app_id='.$this->app_id.'&redirect_uri='.urlencode($callback).'&response_type=code&scope='.$scope.'&state='.$state.'#wechat_redirect';
    }

    public function getOauthQrcode()
    {
        return self::OAUTH_PREFIX.self::QRCODE_URL.'app_id=' .$this->app_id .'&scope=user_info,user_video_publish&response_type=code&redirect_uri='.$this->callback.'&state=your_state&qr_size=300';
    }
}